#!/bin/bash

token=`kubeadm token list|sed -n '2,2p'|awk '{print $1}'`
if [ ! -n "$token" ]
then
    $token = `kubeadm token create`
fi
echo -e "token:\t${token}"

sha=`openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'`

echo -e "sha256:\t${sha}"

ip=`ifconfig eth0|grep -Po 'inet ([0-9]*\.){3}[0-9]+'|awk '{print $NF}'`

echo -e "ip:\t${ip}"

echo -e "cmd:\tkubeadm join ${ip}:6443 --token ${token} --discovery-token-ca-cert-hash sha256:${sha}"